import http from '@/api/http'
import store from '@/store/index'

// 上传用户图片
export const upload = (filePath) => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: http.config.baseUrl + '/common/upload', //仅为示例，非真实的接口地址
			fileType: 'image',
			filePath: filePath,
			name: 'file',
			header: {token: store.state.token},
			complete: (response) => {
				let statusCode = response.statusCode
				if (statusCode === 200) {
					resolve(JSON.parse(response.data))
				} else if (statusCode === 401) {
					return uni.navigateTo({url: '/pages/login/index'})
				} else {
					reject(JSON.parse(response.data))
				}
			}
		})
	})
}

// 登录页面附加信息
export const sendsms = (data) => {
	return http.post('/sms/send',data)
}

// 登录页面附加信息
export const detail = () => {
	return http.get('/user/detail')
}
//获取地址
export const getLocation = (data) => {
	return http.post('/user/getLocation', data)
}

// 用户三方登陆
export const thirdLogin = (data) => {
    return http.post('/index/third', data)
}

// 用户账号密码登陆
export const login = (data) => {
    return http.post('/user/login', data)
}

// 退出登陆
export const logout = (data) => {
    return http.post('/user/logout')
}
// 注销用户
export const delUser = (data) => {
    return http.post('/user/delUser')
}
// 用户账号密码注册
export const register = (data) => {
    return http.post('/user/register', data)
}

// 用户找回密码
export const resetpwd = (data) => {
    return http.post('/user/resetpwd', data)
}

// 用户信息
export const index = () => {
    return http.get('/user/index')
}

// 更新用户信息
export const profile = (data) => {
    return http.post('/user/profile', data)
}


// 获取用户已绑定设备信息
export const changePwd = (data) => {
    return http.post('/user/changePwd',data)
}



//商家资料
export const changeprofile = (data) => {
	return http.post('/user/changeprofile', data)
}

//商家资料
export const changealliance = (data) => {
	return http.post('/user/changealliance', data)
}

export const joinalliance = (data) => {
	return http.post('/user/joinalliance', data)
}



// 用户优惠券信息
export const coupons = (data) => {
    return http.post('/user/coupons', data)
}

// 用户优惠券转赠
export const couponGive = (data) => {
    return http.post('/user/give', data)
}

//关注商家
export const followShop = (option) => {
    return http.post('/user/followShop', option)
}

//关注商品
export const followProduct = (option) => {
    return http.post('/user/followProduct', option)
}



// 关注商家列表
export const followShopList = () => {
    return http.get('/user/followShopList')
}

// 关注商品列表
export const followProductList = () => {
    return http.get('/user/followProductList')
}

//关注物料商品
export const followShopProduct = (option) => {
    return http.post('/user/followShopProduct', option)
}

// 关注物料商品列表
export const followShopProductList = () => {
    return http.get('/user/followShopProductList')
}

// 小程序二维码
export const weappQrcode = () => {
    return http.get('/Appqrcode/weappQrcode')
}

// 用户粉丝
export const fansList = () => {
    return http.get('/user/fansList')
}

//抢红包
export const distribute = (option={}) => {//导航
    return http.post('/user/distribute', option)
}

// 用户粉丝
export const fansChild = (data) => {
    return http.get('/user/fansChild',data)
}
// 新用户页面微信分享领券
export const firstReceive = () => {
    return http.get('/user/firstReceive')
}
// 获取商户发放的优惠券
export const getShopScoupons = (data) => {
    return http.post('/user/drawShopCoupon',data)
}


// 获取商户发放的优惠券
export const generateCoupon = (data) => {
    return http.post('/user/generateCoupon',data)
}

// 新用户页面微信分享领券
export const getuserPrize = () => {
    return http.get('/user/getuserPrize')
}

export const userPrizeLog = () => {
    return http.get('/user/userPrizeLog')
}

export const alipay = (params) => {
    return http.post('/demo/index',params)
}

// 新用户页面微信分享领券
export const setuserPrize = (params) => {
    return http.post('/user/setuserPrize',params)
}
// 更新用户信息
export const getUrl = (data) => {
    return http.post('/user/getUrl', data)
}
export const getDataokeUrl = (data) => {
    return http.post('/user/getDataokeUrl', data)
}

// 默认全部导出  import api from '@/common/vmeitime-http/'
export default {
	alipay,
	fansChild,
	sendsms,
	detail,
	resetpwd,
	upload,
	login,
	logout,
	register,
	thirdLogin,
	index,
	profile,
	coupons,
	getShopScoupons,
	couponGive,
	followShop,
	followShopList,
	followProduct,
	followProductList,
	weappQrcode,
	fansList,
	firstReceive,
	changeprofile,
	changePwd,
	distribute,
	getuserPrize,
	setuserPrize,
	userPrizeLog,
	changealliance,
	joinalliance,
	generateCoupon,
	getLocation,
	getUrl,
	delUser,
	getDataokeUrl
}